package com.lcz.study_designmode.行为模式.备忘录模式.黑箱备忘录;


/**
 * <pre>
 * <img width="128" height="110" src="https://tse3-mm.cn.bing.net/th/id/OIP-C.en-w_oH-yn2UsSRfWnOsGAHaGY?w=198&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7" alt="马刺">
 * 作者:     <a href="https://github.com/liuchuanzheng">刘传政</a>
 * 创建时间:  14:33 2022/6/27 0027
 * QQ:      1052374416
 * 电话:     18501231486
 * 描述:
 * </pre>
 */
public class GameRole {
    int vit;//生命力
    int alk;//攻击力
    int def;//防御力

    public void initState() {
        this.vit = 100;
        this.alk = 100;
        this.def = 100;
    }

    public void fight() {
        this.vit = 0;
        this.alk = 0;
        this.def = 0;
    }

    public IMemento saveState() {
        return new RoleStateMemento(vit, alk, def);
    }

    public void recoverState(IMemento iMemento) {
        RoleStateMemento roleStateMemento = (RoleStateMemento) iMemento;
        vit = roleStateMemento.vit;
        alk = roleStateMemento.alk;
        def = roleStateMemento.def;
    }

    @Override
    public String toString() {
        return "GameRole{" +
                "vit=" + vit +
                ", alk=" + alk +
                ", def=" + def +
                '}';
    }

    private class RoleStateMemento implements IMemento {
        int vit;//生命力
        int alk;//攻击力
        int def;//防御力

        public RoleStateMemento(int vit, int alk, int def) {
            this.vit = vit;
            this.alk = alk;
            this.def = def;
        }
    }
}
